# author: alex
# time: 2022/4/26 19:59
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
import os

from testCase.login import Login_test
from testCase.register import Register_test
from testCase.review import Review_test
from testCase.reply import Reply_test
from testCase.search import Search_test
from testCase.setting import Setting_test
from testCase.thumbUp import ThumbUp_test

from testCase.login_interface import Login_interface_test
from testCase.register_interface import Register_interface_test

def test_login_ui():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    login_cases = loader.getTestCaseNames(Login_test)
    for item in login_cases:
        suite.addTest(Login_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    print(base_dir)
    dir_path = base_dir + "/result/"
    now = time.strftime("%Y-%m-%d %H_%M_%S")
    report_path = dir_path + "login_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="login_ui_test报告", description="selenium测试")
        runner.run(suite)

def test_register_ui():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    register_cases = loader.getTestCaseNames(Register_test)
    for item in register_cases:
        suite.addTest(Register_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    print(base_dir)
    dir_path = base_dir + "/result/"
    now = time.strftime("%Y-%m-%d %H_%M_%S")
    report_path = dir_path + "register_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="register_ui_test报告", description="selenium测试")
        runner.run(suite)

def test_review_ui():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    review_cases = loader.getTestCaseNames(Review_test)
    for item in review_cases:
        suite.addTest(Review_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    print(base_dir)
    dir_path = base_dir + "/result/"
    now = time.strftime("%Y-%m-%d %H_%M_%S")
    report_path = dir_path + "review_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="review_ui_test报告", description="selenium测试")
        runner.run(suite)

def test_reply_ui():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    reply_cases = loader.getTestCaseNames(Reply_test)
    for item in reply_cases:
        suite.addTest(Reply_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    dir_path = base_dir + "/result/"
    report_path = dir_path + "reply_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="reply_ui_test报告", description="selenium测试")
        runner.run(suite)

def test_search_ui():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    search_cases = loader.getTestCaseNames(Search_test)
    for item in search_cases:
        suite.addTest(Search_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    dir_path = base_dir + "/result/"
    report_path = dir_path + "search_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="search_ui_test报告", description="selenium测试")
        runner.run(suite)
        
def test_setting_ui():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    setting_cases = loader.getTestCaseNames(Setting_test)
    for item in setting_cases:
        suite.addTest(Setting_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    dir_path = base_dir + "/result/"
    report_path = dir_path + "setting_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="setting_ui_test报告", description="selenium测试")
        runner.run(suite)

def test_thumb_ui():
    suite = unittest.TestSuite()
    suite.addTest(ThumbUp_test('test_thumbUp'))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    dir_path = base_dir + "/result/"
    report_path = dir_path + "thumb_ui_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="thumb_ui_test报告", description="selenium测试")
        runner.run(suite)

def test_login_interface():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    login_interface_cases = loader.getTestCaseNames(Login_interface_test)
    for item in login_interface_cases:
        suite.addTest(Login_interface_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    dir_path = base_dir + "/result/"
    report_path = dir_path + "login_interface_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="login_interface_test报告", description="接口测试")
        runner.run(suite)

def test_register_interface():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    register_interface_cases = loader.getTestCaseNames(Register_interface_test)
    for item in register_interface_cases:
        suite.addTest(Register_interface_test(item))

    base_dir = os.path.dirname(os.path.realpath(__file__))
    dir_path = base_dir + "/result/"
    report_path = dir_path + "register_interface_test.html"
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="register_interface_test报告", description="接口测试")
        runner.run(suite)

if __name__ == "__main__":
    test_login_ui()
    test_register_ui()
    test_review_ui()
    test_reply_ui()
    test_search_ui()
    test_setting_ui()
    test_thumb_ui()
    test_login_interface()
    test_register_interface()